package my.jieh.tips.swing;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

public class MultiColumnListLeaders {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Leaders");
    frame.setDefaultCloseOperation(
      JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    String headers[] = {"Leader", "Country"};
    String data[][] = {
      {"Tony Blair", "England"},
      {"Thabo Mbeki", "South Africa"},
      {"Megawati Soekarnoputri", "Indonesia"},
      {"Hosni Mubarak", "Egypt"},
      {"Vladimir Putin", "Russia"},
      {"Vicente Fox", "Mexico"},
      {"Ariel Sharon", "Israel"}
    };
    TableModel model =
      new DefaultTableModel(data, headers) {
        // Make read-only
        public boolean isCellEditable(int x, int y) {
          return false;
        }
      };
    JTable table = new JTable(model);
    // Set selection to first row
    ListSelectionModel selectionModel =
      table.getSelectionModel();
    selectionModel.setSelectionInterval(0, 0);
    selectionModel.setSelectionMode(
      ListSelectionModel.SINGLE_SELECTION);
    // Add to screen so scrollable
    JScrollPane scrollPane = new JScrollPane (table);
    contentPane.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 100);
    frame.show();
  }
}

